<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>


<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
  String ctxPath = request.getContextPath();
%>

<jsp:useBean id="packageSearchForm" type="org.apache.struts.validator.DynaValidatorForm" scope ="request"/>

<jsp:useBean id="packageSearchView" type="com.broadvision.web.util.ViewDynaBean" scope ="request"/>

<script language="JavaScript" src="<%= ctxPath %>/bp/js/user_popup_funcs.js"></script>

<script language="JavaScript">

  function check(field, button) {
    var SelectAllTxt = '<bean-el:message key="button.selectAll" bundle="bp.messages"/>';
    var UnselectAllTxt = '<bean-el:message key="button.unselectAll" bundle="bp.messages"/>';
    if (field == null) {
      button.value = SelectAllTxt;
    }
    var checkflag = "false";
    if (button.value == SelectAllTxt) {
      checkflag = "false";
    }
    if (button.value == UnselectAllTxt) {
      checkflag = "true";
    }
    var max = field.length;
    if (max > 1) {
      if (checkflag == "false") {
        for (i = 0; i < max; i++) {
          field[i].checked = true;
        }
        button.value = UnselectAllTxt;
      } else {
        for (i = 0; i < max; i++) {
          field[i].checked = false;
        }
        button.value = SelectAllTxt;
      }
    } else {
      if (checkflag == "false") {
        field.checked = true;
        button.value = UnselectAllTxt;
      } else {
        field.checked = false;
        button.value = SelectAllTxt;
      }
    }
  }
  
  function updateCheckbox(field, button) {
    var SelectAllTxt = '<bean-el:message key="button.selectAll" bundle="bp.messages"/>';
    var UnselectAllTxt = '<bean-el:message key="button.unselectAll" bundle="bp.messages"/>';
    if (field == null) {
      button.value = SelectAllTxt;
    }
    var checkflag = "false";
    if (button.value == SelectAllTxt) {
      checkflag = "false";
    }
    if (button.value == UnselectAllTxt) {
      checkflag = "true";
    }
    var max = field.length;
    if (max > 1) {
      if (checkflag == "false") {
        for (i = 0; i < max; i++) {
          if (field[i].checked == false) {
            return;
          }
        }
        button.value = UnselectAllTxt;
      } else {
        for (i = 0; i < max; i++) {
          if (field[i].checked == true) {
            return;
          }
        }
        button.value = SelectAllTxt;
      }
    } else {
      if (checkflag == "false") {
        if (field.checked == true) {
          button.value = UnselectAllTxt;
        }
      } else {
        if (field.checked == false) {
          button.value = SelectAllTxt;
        }
      }
    }
  }

  function isAnyChecked(field, alertmsg, confirmmsg) {
    if (field == null) {
      if (alertmsg != null && alertmsg.length > 0) {
        alert(alertmsg);
      }
      return false;
    }
    else if (field.length == null) {
      if (field.checked == false) {
        if (alertmsg != null && alertmsg.length > 0) {
          alert(alertmsg);
        }
        return false;
      }
      else {
        if (confirmmsg != null && confirmmsg.length > 0) {
          return confirm(confirmmsg);
        }
        else {
          return true;
        }
      }
    }
    else {
      for (var j = 0; j < field.length; j++) {
        if (field[j].checked) {
          if (confirmmsg != null && confirmmsg.length > 0) {
            return confirm(confirmmsg);
          }
          else {
            return true;
          }
        }
      }
      if (alertmsg != null && alertmsg.length > 0) {
        alert(alertmsg);
      }
      return false;
    }
  }

  function doPackageOnOffAction(myform, setOnline) {
    var onOfflineMessage = '<bean-el:message key="bp.package.confirm.online" bundle="bp.messages"/>';
    if (setOnline == 0) { 
      onOfflineMessage = '<bean-el:message key="bp.package.confirm.offline" bundle="bp.messages"/>';
    }
    if ( confirm(onOfflineMessage)){
      myform.oneOnly.value = false;
      myform.action = '<html-el:rewrite page="/bp/packageSetOnOffline.do"/>';
      myform.setOnline.value = setOnline;
      myform.forwardAction.value = '/bp/packageSearch.do';
      myform.submit();
    }
    return false;
  }

  function doOnePackageOnOffAction(myform, setOnline, id) {
    myform.oneOnly.value = true;
    myform.action = '<html-el:rewrite page="/bp/packageSetOnOffline.do"/>';
    myform.setOnline.value = setOnline;
    myform.id.value = id;
    myform.forwardAction.value = '/bp/packageSearch.do';
    myform.submit();
    return false;
  }

  function doPackageDeleteAction(myform) {
    if ( confirm('<bean-el:message key="bp.package.confirm.delete" bundle="bp.messages"/>') ){
      myform.oneOnly.value = false;
      myform.action = '<html-el:rewrite page="/bp/packageDelete.do"/>';
      myform.forwardAction.value = '/bp/packageSearch.do';
      myform.submit();
      return true;
    }
  }

  function doOnePackageDeleteAction(myform, id) {
    if ( confirm('<bean-el:message key="bp.package.confirm.delete" bundle="bp.messages"/>') ){
      myform.oneOnly.value = true;
      myform.id.value = id;
      myform.action = '<html-el:rewrite page="/bp/packageDelete.do"/>';
      myform.forwardAction.value = '/bp/packageSearch.do';
      myform.submit();
      return true;
    }
    return false;
  }

  function confirmDelete() {
    if ( confirm('<bean-el:message key="bp.package.confirm.delete" bundle="bp.messages"/>') ){
      return true;
    } else {
      return false;
    }
  }

  function confirmOnOffline(setOnline) {
    var onOfflineMessage = '<bean-el:message key="bp.package.confirm.online" bundle="bp.messages"/>';
    if (setOnline == 0) { 
      onOfflineMessage = '<bean-el:message key="bp.package.confirm.offline" bundle="bp.messages"/>';
    }
    if ( confirm(onOfflineMessage)){
      return true;
    } else {
      return false;
    }
  }

function setUserAlias(formName, fieldName, fieldValue) {
  // this page does not have any hidden fields that rely on the popup,
  // we do not need a refresh url.
  var refreshUrl = null;
  setFieldValue(refreshUrl, formName, fieldName, fieldValue);
}
  
</script>

<!-- Zone 5 starts here.  -->

<c:set var="editImg">
<img src="<%= ctxPath %>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="mc.messages"/>">
</c:set>
<c:set var="offlineImg">
<img src="<%= ctxPath %>/mc/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOffline" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.setOffline" bundle="mc.messages"/>">
</c:set>
<c:set var="onlineImg">
<img src="<%= ctxPath %>/mc/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOnline" bundle="mc.messages"/>" title="<bean-el:message key="image.alt.setOnline" bundle="mc.messages"/>">
</c:set>

<html-el:form action="/bp/packageSearch.do" >

<html-el:hidden name="packageSearchForm" property="showResult" value="true"/>

<input type="hidden" name="oneOnly" />
<input type="hidden" name="setOnline" />
<input type="hidden" name="id" />
<input type="hidden" name="forwardAction" />
		  
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message key="bp.package.contentArea" bundle="bp.messages"/>">
  <tr>
    <td valign="top" width="100%">
		    
      <div class="pageTitle"><bean-el:message key="bp.package.packageSearch.title"  bundle="bp.messages"/></div> 
		 
      <div class="pageSubtitle">
	<span class="left"><bean-el:message key="bp.package.packageSearch.searchCriteria" bundle="bp.messages"/></span>
	<span class="right">&nbsp;</span>
      </div> 

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message key="bp.package.packageSearch.summary" bundle="bp.messages"/>">
	<tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.packageName" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
            <html-el:text name="packageSearchForm" property="name" size="31" maxlength="80" />
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.packageStatus" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
            <html-el:checkbox name="packageSearchForm" property="online" value="1">
               <bean-el:message key="bp.package.status.online" bundle="bp.messages"/>
            </html-el:checkbox>
            <html-el:checkbox name="packageSearchForm" property="offline" value="1">
               <bean-el:message key="bp.package.status.offline" bundle="bp.messages"/>
            </html-el:checkbox>
            <html-el:checkbox name="packageSearchForm" property="inDeployment" value="1">
               <bean-el:message key="bp.package.status.inDeployment" bundle="bp.messages"/>
            </html-el:checkbox>
            <html-el:checkbox name="packageSearchForm" property="toBeConfig" value="1">
               <bean-el:message key="bp.package.status.toBeConfig" bundle="bp.messages"/>
            </html-el:checkbox>
            <html-el:checkbox name="packageSearchForm" property="error" value="1">
               <bean-el:message key="bp.package.status.error" bundle="bp.messages"/>
            </html-el:checkbox>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%"><bean-el:message key="bp.package.deployerID" bundle="bp.messages"/>:</td>
          <td class="labelField" width="80%">
            <html-el:text name="packageSearchForm" property="deployer"
size="31" maxlength="80" />

              <input type="button" name="browse" class="pageButton"
                onClick="JavaScript:findUserPopup(
                    '<html-el:rewrite page="/mt/userSearchPopup.do"/>',
                    'packageSearchForm','deployer');" value='<bean-el:message key="button.browse" bundle="bp.messages"/>'>

          </td>
        </tr>
      </table>
	
      <div class="pageButtonWrap" align="right">
        <html-el:submit styleClass="pageButton">
          <bean-el:message key="button.showResults" bundle="bp.messages"/>
        </html-el:submit>
      </div>

      <logic:notEqual name="packageSearchView" property="packageCount" value="-1">
        <br>


<% 
String pkgCount = String.valueOf(((Integer) packageSearchView.get("packageCount")).intValue());
%>
        <div class="pageSubtitle">
          <span class="left"><bean-el:message
key="bp.package.packageSearch.resultFound" arg0="<%= pkgCount %>"  bundle="bp.messages"/></span>
          <span class="right">&nbsp;</span>
        </div> 

        <!--end page title area here-->

        <logic:equal name="packageSearchView" property="packageCount" value="0">
          <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="<bean-el:message key="bp.package.packageSearch.resultSummary" bundle="bp.messages"/>" width="100%">
            <tr class="listHeader">
              <th id="PackageName" align="left"><bean-el:message key="bp.package.packageName"  bundle="bp.messages"/></th>
              <th id="Status" align="left"><bean-el:message key="bp.package.packageStatus"  bundle="bp.messages"/></th>
              <th id="Deployer" align="left"><bean-el:message key="bp.package.deployerID"  bundle="bp.messages"/></th>
              <th id="Version" align="left"><bean-el:message key="bp.package.version"  bundle="bp.messages"/></th>
              <th id="Actions" align="left" nowrap><bean-el:message key="header.actions"  bundle="bp.messages"/></th>
            </tr>
            <tr class="listEven">
              <td colspan="5" align="center">
                <bean-el:message key="bp.package.packageSearch.noPackage" bundle="bp.messages"/>
              </td>
            </tr>
           </table>
         </logic:equal>
      <!-- Start List here -->

        <logic:notEqual name="packageSearchView" property="packageCount" value="0">
         <logic:equal name="packageSearchView" property="canEdit" value="true">

          <div class="globalButtonWrap">
            <input type="button" name="selectAllPackages" class="globalButton" onclick="check(this.form.packageIds, this);" value='<bean-el:message key="button.selectAll" bundle="bp.messages"/>'>

            <input type="button" name="setonline" class="globalButton" 
              onclick="if (isAnyChecked(this.form.packageIds, '<bean-el:message key="bp.package.alert.atLeastOne" bundle="bp.messages"/>', '')) doPackageOnOffAction(this.form, 1);" 
              value='<bean-el:message key="button.setOnline" bundle="bp.messages"/>'>
            <input type="button" name="setoffline" class="globalButton" 
              onclick="if (isAnyChecked(this.form.packageIds, '<bean-el:message key="bp.package.alert.atLeastOne" bundle="bp.messages"/>', '')) doPackageOnOffAction(this.form, 0);" 
              value='<bean-el:message key="button.setOffline" bundle="bp.messages"/>'>

          </div>
			
          <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="<bean-el:message key="bp.package.packageSearch.resultSummary" bundle="bp.messages"/>" width="100%">
            <tr class="listHeader">
              <th id="Checkboxes" align="left">&nbsp;</th> 
              <th id="PackageName" align="left"><bean-el:message key="bp.package.packageName"  bundle="bp.messages"/></th>
              <th id="Status" align="left"><bean-el:message key="bp.package.packageStatus"  bundle="bp.messages"/></th>
              <th id="Deployer" align="left"><bean-el:message key="bp.package.deployerID"  bundle="bp.messages"/></th>
              <th id="Version" align="left"><bean-el:message key="bp.package.version"  bundle="bp.messages"/></th>
              <th id="Actions" align="left" nowrap><bean-el:message key="header.actions"  bundle="bp.messages"/></th>
            </tr>

            <logic:iterate id="pkg" name="packageSearchView" property="packages" indexId="i">

            <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">

	      <logic:notEqual name="pkg" property="deployStatus" value="1">
                  <td id="Checkboxes" align="center">
                  </td> 
              </logic:notEqual>
	      <logic:equal name="pkg" property="deployStatus" value="1">
                <td id="Checkboxes" align="center">
                  <input type="checkbox" name="packageIds" onclick="updateCheckbox(this.form.packageIds, this.form.selectAllPackages);" value="<c:out value="${pkg.map.id}"/>">
                </td> 
              </logic:equal>


              <td headers="PackageName">
	           <html-el:link page="/bp/packageView.do" paramId="id" paramName="pkg" paramProperty="id" >
                     <c:out value="${pkg.map.name}"/>
                   </html-el:link>
              </td>
              <td headers="Status">
                   <c:out value="${pkg.map.displayStatusString}"/>
              </td>
              <td headers="Deployer">
                  <c:out value="${pkg.map.deployer}"/>
              </td>
              <td headers="Version">
                   <c:out value="${pkg.map.userInputVersion}"/>
              </td>

              <td nowrap align="left" headers="Actions">

                <logic:equal name="pkg" property="deployStatus" value="1">
	            <html-el:link page="/bp/packageEdit.do" paramId="id" paramName="pkg" paramProperty="id" >
                      <c:out value='${editImg}' escapeXml="false"/>
                   </html-el:link>

                   <logic:equal name="pkg" property="status" value="1">
                     <a href="#" onclick="if (confirmOnOffline(0)) doOnePackageOnOffAction(document.packageSearchForm, 0, '<c:out value="${pkg.map.id}"/>');"><c:out value='${offlineImg}' escapeXml="false"/></a>
                   </logic:equal>
                   <logic:notEqual name="pkg" property="status" value="1">
                     <a href="#" onclick="if (confirmOnOffline(1)) doOnePackageOnOffAction(document.packageSearchForm, 1, '<c:out value="${pkg.map.id}"/>');"><c:out value='${onlineImg}' escapeXml="false"/></a>
                   </logic:notEqual>
                </logic:equal>

	          <logic:equal name="pkg" property="deployStatus" value="3">
                    <html-el:link page="/bp/packageEdit.do" paramId="id" paramName="pkg" paramProperty="id" >
                      <c:out value='${editImg}' escapeXml="false"/>
                    </html-el:link>
                  </logic:equal>
                </td>
              </tr>
            </logic:iterate>
          </table>
        </logic:equal>
        <!-- canEdit true -->

        <logic:notEqual name="packageSearchView" property="canEdit" value="true">
          <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="<bean-el:message key="bp.package.packageSearch.resultSummary" bundle="bp.messages"/>" width="100%">
            <tr class="listHeader">
              <th id="PackageName" align="left"><bean-el:message key="bp.package.packageName"  bundle="bp.messages"/></th>
              <th id="Status" align="left"><bean-el:message key="bp.package.packageStatus"  bundle="bp.messages"/></th>
              <th id="Deployer" align="left"><bean-el:message key="bp.package.deployerID"  bundle="bp.messages"/></th>
              <th id="Version" align="left"><bean-el:message key="bp.package.version"  bundle="bp.messages"/></th>
            </tr>

            <logic:iterate id="pkg" name="packageSearchView" property="packages" indexId="i">
            <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
              <td headers="PackageName">
	        <html-el:link page="/bp/packageView.do" paramId="id" paramName="pkg" paramProperty="id" >
                  <c:out value="${pkg.map.name}"/>
                </html-el:link>
              </td>
              <td headers="Status">
                <c:out value="${pkg.map.displayStatusString}"/>
              </td>
              <td headers="Deployer">
                <c:out value="${pkg.map.deployer}"/>
              </td>
              <td headers="Version">
                <c:out value="${pkg.map.userInputVersion}"/>
              </td>
            </tr>
            </logic:iterate>
          </table>
        </logic:notEqual>
        <!-- canEdit false -->

        </logic:notEqual> <!-- resultCount not equal to 0 -->
      </logic:notEqual> <!-- resultCount not equal to -1 -->

      <!--end list here-->
    </td>
  </tr>
</table>

</html-el:form>


<!--end zone 5 content here -->

